/**
 * @FileName ConcreteFactory.java
 * @Package com.designMode.factoryMethod
 * -------------------------------------
 * @function Please write description of function
 * @Date 2016-1-5 下午2:35:48
 * -------------------------------------
 * Copyright (c) 2016,顾博君 All Rights Reserved.
 */
package com.designMode.factoryMethod;

/**
 * @author 顾博君
 * @ClassName ConcreteFactory
 * @Date 2016-1-5 下午2:35:48
 * @Function 具体工厂类
 */
public class ConcreteFactory extends Factory {
    /**
     * 利用反射机制，生产产品，这样写结合了抽象工厂模式的优点，又保留了工厂方法模式的优点，让子类决定实例化
     *
     * @return 产品
     */
    @Override
    public Product createProduct(Class<? extends Product> c) {
        Product product = null;
        try {
            product = (Product) Class.forName(c.getName()).newInstance();
        } catch (Exception e) {
            // 异常处理
            e.printStackTrace();
        }
        return product;
    }
}
